home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261a.zoo / genclass.tcsh < prev    next >
Encoding:
Text File  |  1994-11-16  |  10.7 KB  |  451 lines

  1. #!/usr/local/bin/tcsh
  2.  
  3. #   Copyright (C) 1989 Free Software Foundation, Inc.
  4. #   
  5. #   genclass program enhanced by Wendell C. Baker 
  6. #   (original by Doug Lea (dl@rocky.oswego.edu))
  7.  
  8. #This file is part of GNU libg++.
  9.  
  10. #GNU libg++ is free software; you can redistribute it and/or modify
  11. #it under the terms of the GNU General Public License as published by
  12. #the Free Software Foundation; either version 1, or (at your option)
  13. #any later version.
  14.  
  15. #GNU libg++ is distributed in the hope that it will be useful,
  16. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #GNU General Public License for more details.
  19.  
  20. #You should have received a copy of the GNU General Public License
  21. #along with GNU libg++; see the file COPYING.  If not, write to
  22. #the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. set echo_style=both
  25. #
  26. # genclass -list [proto ...]
  27. # genclass -catalog [proto ...]
  28. # genclass type1 {ref|val} proto [out_prefix]
  29. # genclass -2 type1 {ref|val} type2 {ref, val} proto [out_prefix]
  30. #
  31. # Generate classes from prototypes
  32. #
  33. set name=genclass ;
  34. set usage="\n    $name -list [proto ...]\n    $name -catalog [proto ...]\n    $name type1 {ref|val} proto [out_prefix]\n    $name -2 type1 {ref|val} type2 {ref|val} proto [out_prefix]"
  35.  
  36. switch ("$1")
  37. case -usage:
  38.     #
  39.     # -usage
  40.     #
  41.     echo "usage: $usage";
  42.     exit 0;
  43.     breaksw
  44. case -version:
  45.     #
  46.     # -version
  47.     #
  48.     # <VERSION> is substituted by the build process.
  49.     # We currently use the libg++ version number (extracted from ../Makefile).
  50.     echo "$name: version 2.5.2" ;
  51.     exit 0;
  52.     breaksw;
  53. case -requires:
  54.     #
  55.     # -requires
  56.     #
  57.     # The following line should contain any nonstandard programs
  58.     # which must be in the users's path (i.e. not referenced by a
  59.     # fullpath);it allows one to check a script for dependencies
  60.     # without exhaustively testing its usages.
  61.     # ... in this case genclass depends on nothing else.
  62.     echo ;
  63.     exit 0;
  64.     breaksw;
  65. endsw
  66.  
  67. # pull it in from the environment
  68. #[ "$TRACE" = "" ] || set -xv 
  69.  
  70. # Search in standard g++ prototype directory and in the current directory
  71. # NOTE: this variable is edited by the install process
  72. set PROTODIR=/usr/local/lib/c++proto
  73.  
  74. set pwd=$PWD ;
  75.  
  76. switch ("$1")
  77. case -list:   #*|-catalog*:
  78.     #
  79.     # genclass -catalog [proto ...]
  80.     # genclass -list [proto ...]
  81.     #
  82.     set option="$1" ;
  83.     shift ;
  84.  
  85.     switch ($#)
  86.     case 0:
  87.         #
  88.         # -catalog
  89.         # -list
  90.         #
  91.         set select=all ;
  92.         set select_pattern=p ;
  93.         breaksw
  94.     default:
  95.         #
  96.         # -catalog proto ...
  97.         # -list proto ...
  98.         #
  99.         set select="$@" ;
  100.         select_pattern= ;
  101.         foreach i ($@)
  102.             set select_pattern="\
  103. $select_pattern\
  104. /.*$i\$/ p\
  105. " ;
  106.         end ;
  107.  
  108.         breaksw
  109.     endsw
  110.  
  111.     #
  112.     # select_pattern is now a (possibly-vacuous) newline-
  113.     # separated list of patterns of the form:
  114.     #
  115.     #     /.*Proto1$/ p
  116.     #     /.*Proto2$/ p
  117.     #     /.*Proto3$/ p
  118.     #
  119.     # or select_pattern is simply ``p'' to select everything
  120.  
  121.     # Hmmm... not all systems have a fmt program; should we
  122.     # just go ahead and use ``nroff -Tcrt | cat -s'' here?
  123.     set fmt='nroff -Tcrt | cat -s'
  124.     #fmt=fmt ;
  125.  
  126.     switch ("$option")
  127.     case -catalog:
  128.         #
  129.         # -catalog [proto ...]
  130.         #
  131.         echo "\
  132. Catalog of ${name} class templates\
  133. directories searched:\
  134.     $PROTODIR\
  135.     $pwd\
  136. selecting: $select\
  137. classes available:" ;
  138.         breaksw
  139.     case -list:
  140.         #
  141.         # -list [proto ...]
  142.         #
  143.         # no need to do anything (the list is coming out next)
  144.         breaksw
  145.     endsw 
  146.  
  147. # The sed script does the following:
  148. # - If it does not end in a .ccP or .hP then
  149. #   it's not a template and we are not intereseted.
  150. # - Get rid of pathname components [s;.*/;;]
  151. # - Just take the template names
  152. # - change quoting conventions and select off what we want to see
  153. # -if it did not pass the patterns, kill it
  154.  
  155.     ls $pwd $PROTODIR | sed -ne '\
  156. /\.ccP$/ !{ \
  157.    /\.hP$/ !{ \
  158.      d \
  159.    } \
  160. } \
  161. s;.*/;;\
  162. s/\.ccP$//\
  163. s/\.hP$//\
  164. ' -e "$select_pattern" | sort -u | switch ("$option")
  165.     case -catalog:
  166.         # The library catalog information preceded the list
  167.         # format the list, and tab in in a bit to make it readable.
  168.         # Re-evaluate $fmt because it might contain a shell command
  169.         eval $fmt | sed -e 's/.*/    &/' ;
  170.         breaksw
  171.     case -list:
  172.         # nothing special, just let the sorted list dribble out
  173.         # we must use cat to receive (and reproduce) the incoming list
  174.         cat ;
  175.         breaksw
  176.     exit 0;
  177.     breaksw
  178. case -2:
  179.     #
  180.     # genclass -2 type1 {ref|val} type2 {ref|val} proto [out_prefix]
  181.     #
  182.     set N=2 ;
  183.  
  184.     switch ($#)
  185.     case [6]: # genclass -2 type1 {ref|val} type2 {ref|val} proto
  186.        breaksw
  187.     case [7]: # genclass -2 type1 {ref|val} type2 {ref|val} proto out_prefix
  188.        breaksw
  189.     default:
  190.     echo "usage: $usage"  ;
  191.     exit 1;
  192.     breaksw;
  193.     endsw
  194.     shift ;
  195.     breaksw
  196. default:
  197.     #
  198.     # genclass type1 {ref|val} proto [out_prefix]
  199.     #
  200.     set N=1 ;
  201.  
  202.     switch ($#)
  203.     case [3]: # genclass type1 {ref|val} proto
  204.        breaksw;
  205.     case [4]: # genclass type1 {ref|val} proto out_prefix
  206.        breaksw;
  207.     default:
  208.     echo "usage: $usage"  ;
  209.     exit 1;
  210.     breaksw
  211.     endsw
  212.     breaksw
  213. endsw
  214.  
  215. #
  216. # Args are now (the point being the leading ``-2'' is gone)
  217. #
  218. #     type1 {ref|val} proto [out_prefix]
  219. #     type1 {ref|val} type2 {ref|val} proto [out_prefix]
  220. #
  221.  
  222. #
  223. # Quote all of the $1 $2 etc references to guard against
  224. # dynamic syntax errors due to vacuous arguments (i.e. '')
  225. # as sometimes occurs when genclass is used from a Makefile
  226. #
  227.  
  228. set T1="$1";
  229. set T1NAME="${T1}." ;
  230. set T1SEDNAME="$T1" ;
  231.  
  232. switch ("$2")
  233. case ref:
  234.      set T1ACC="\&" ;
  235.      breaksw
  236. case val:
  237.      set T1ACC=" " ;
  238.      breaksw
  239. default:
  240.     echo "${name}: Must specify type1 access as ref or val"  ;
  241.     echo "usage: $usage"  ;
  242.     exit 1
  243.     breaksw
  244. endsw
  245.  
  246. # N is either 1 or 2
  247.  
  248. switch ($N)
  249. case 1:
  250.     #
  251.     # type1 {ref|val} proto [out_prefix]
  252.     #
  253.     set class="$3" ;
  254.  
  255.     set T2="" ;
  256.     set T2ACC="" ;
  257.     set T2NAME="";
  258.     breaksw
  259. case 2:
  260.     #
  261.     # type1 {ref|val} type2 {ref|val} proto [out_prefix]
  262.     #
  263.     set class="$5" ;
  264.  
  265.     set T2="$3";
  266.     set T2NAME="$T2." ;
  267.     set T2SEDNAME="$T2" ;
  268.  
  269.     switch ("$4")
  270.     case ref:
  271.         set T2ACC="\&" ;
  272.         breaksw;
  273.     case val:
  274.         set T2ACC=" " ;
  275.         breaksw;
  276.     default:
  277.         echo "${name}: Must specify type2 access: ref or val"  ;
  278.     echo "usage: $usage"  ;
  279.     exit 1;
  280.     breaksw;
  281.     endsw
  282. endsw
  283.  
  284. set defaultprefix="$T1NAME$T2NAME" ;
  285.  
  286. switch ($#)
  287. case [3]:  # type1 {ref|val} proto
  288.     set replaceprefix="N" ;
  289.     set prefix="$defaultprefix" ;
  290.     breaksw;
  291. case [5]:  # type1 {ref|val} type2 {ref|val} proto
  292.     set replaceprefix="N" ;
  293.     set prefix="$defaultprefix" ;
  294.     breaksw;
  295. case [4]:  # type1 {ref|val} proto out_prefix
  296.     set prefix="$4" ;
  297.     set replaceprefix="Y" ;
  298.     breaksw;
  299. case [6]:  # type1 {ref|val} type2 {ref|val} proto out_prefix
  300.     set prefix="$6" ;
  301.     set replaceprefix="Y" ;
  302.     breaksw;
  303. default:
  304.     echo "${name}: too many arguments"  ;
  305.     echo "usage: $usage"  ;  
  306.     exit 1;
  307.     breaksw;
  308. endsw ;
  309.  
  310. set src_h=$class.hP
  311. set src_cc=$class.ccP
  312. set out_h=$prefix$class.h;
  313. set out_cc=$prefix$class.cc ;
  314.  
  315. #
  316. # Note #1: The .h and .cc parts are done separately
  317. #     in case only a .h exists for the prototype
  318. #
  319. # Note #2: Bind the .h and .cc parts to the fullpath
  320. #     directories at the same time to ensure consistency.
  321. #
  322.  
  323. if (-f $pwd/$src_h) then
  324.     set fullsrc_h=$pwd/$src_h ;
  325.     set fullsrc_cc=$pwd/$src_cc ;
  326. else if ( -f $PROTODIR/$src_h ) then
  327.     set fullsrc_h=$PROTODIR/$src_h ;
  328.     set fullsrc_cc=$PROTODIR/$src_cc ;
  329. else
  330.     echo "${name}: there is no prototype for class $class - file $src_h"  ;
  331.     $0 -list ;
  332.     exit 1;
  333. endif
  334.  
  335. set CASES="$N$replaceprefix" ;
  336. # CASES is one of { 2Y 2N 1Y 1N }
  337.  
  338. #
  339. # WATCHOUT - we have no way of checking whether or not
  340. # the proper case type is being used with the prototype.
  341. #
  342. # For example, we have no way of ensuring that any of
  343. # Map variants are specified with the -2 argument set
  344. # Further, we have no way of ensuring that -2 is not
  345. # used with the prototypes which require only one.
  346. #
  347. # The second problem is not serious because it still
  348. # results in correctly-generated C++ code; the first
  349. # problem is serious because it results in C++ code that
  350. # still has ``<C>'' and ``<C&>'' syntax inside it.  Such
  351. # code of course will not compile.
  352. #
  353. # SO THE BEST WE CAN DO - is check for the presence of
  354. # <C> and <C&> AFTER the thing has been generated.
  355. #
  356.  
  357. switch ($CASES)
  358. case 2Y: # Two output substitutions, change the prefix
  359.     sed < $fullsrc_h > $out_h -e "\
  360. s/<T>/$T1/g\
  361. s/<T&>/$T1$T1ACC/g\
  362. s/<C>/$T2/g\
  363. s/<C&>/$T2$T2ACC/g \
  364. s/$T1SEDNAME\.$T2SEDNAME\./$prefix/g\
  365. s/$T1SEDNAME\./$prefix/g\
  366. s/$T2SEDNAME\./$prefix/g\
  367. " ;
  368.     breaksw;
  369. case 2N: # Two output substitutions, use the default prefix
  370.     sed < $fullsrc_h > $out_h -e "\
  371. s/<T>/$T1/g\
  372. s/<T&>/$T1$T1ACC/g\
  373. s/<C>/$T2/g\
  374. s/<C&>/$T2$T2ACC/g\
  375. " ;
  376.     breaksw;
  377. case 1Y: # One output substitution, change the prefix
  378.     sed < $fullsrc_h > $out_h -e "
  379. s/<T>/$T1/g\
  380. s/<T&>/$T1$T1ACC/g\
  381. s/$T1SEDNAME\./$prefix/g\
  382. " ;
  383.     breaksw;
  384. case 1N: # One output substitution, use the default prefix
  385.     sed < $fullsrc_h > $out_h -e "\
  386. s/<T>/$T1/g\
  387. s/<T&>/$T1$T1ACC/g\
  388. " ;
  389.     breaksw;
  390. endsw
  391.  
  392. fgrep '<C&?>' $out_h > /dev/null
  393. if ( $? == 0) then
  394.     echo "${name}: the $class class requires the -2 syntax for the 2nd type"  ;
  395.     echo "usage: $usage"  ;
  396.     # the user does not get to see the mistakes (he might try to compile it)
  397.     rm $out_h ;
  398.     exit 1;
  399. endif
  400.  
  401. if ( ! -f $fullsrc_cc ) then
  402.     echo "${name}: warning, class has a .h but no .cc file"  ;
  403.     exit 0;
  404. endif
  405.  
  406. switch ($CASES)
  407. case 2Y: # Two output substitutions, change the prefix
  408.     sed < $fullsrc_cc > $out_cc -e "\
  409. s/<T>/$T1/g\
  410. s/<T&>/$T1$T1ACC/g\
  411. s/<C>/$T2/g\
  412. s/<C&>/$T2$T2ACC/g\
  413. s/$T1SEDNAME\.$T2SEDNAME\./$prefix/g\
  414. s/$T1SEDNAME\./$prefix/g\
  415. s/$T2SEDNAME\./$prefix/g\
  416. "
  417.     breaksw;
  418. case 2N: # Two output substitutions, use the default prefix
  419.     sed < $fullsrc_cc > $out_cc -e "\
  420. s/<T>/$T1/g\
  421. s/<T&>/$T1$T1ACC/g\
  422. s/<C>/$T2/g\
  423. s/<C&>/$T2$T2ACC/g\
  424. "
  425.     breaksw;
  426. case 1Y: # One output substitution, change the prefix
  427.     sed < $fullsrc_cc > $out_cc -e "\
  428. s/<T>/$T1/g\
  429. s/<T&>/$T1$T1ACC/g\
  430. s/$T1SEDNAME\./$prefix/g\
  431. "
  432.     breaksw;
  433. case 1N: # One output substitution, use the default prefix
  434.     sed < $fullsrc_cc > $out_cc -e "\
  435. s/<T>/$T1/g\
  436. s/<T&>/$T1$T1ACC/g\
  437. "
  438.     breaksw;
  439. endsw
  440.  
  441. fgrep '<C&?>' $out_h $out_cc > /dev/null
  442. if ($? == 0) then
  443.     echo "${name}: the $class class requires the -2 syntax for the 2nd type"  ;
  444.     echo "usage: $usage"  ;
  445.     # the user does not get to see the mistakes (he might try to compile it)
  446.     rm $out_h $out_cc ;
  447.     exit 1;
  448. endif ;
  449.  
  450. exit 0;
  451.